import { createApp } from 'vue'
import App from './App.vue'
import naive from 'naive-ui'
import router from './router'
import { Request } from '@/utils/request';
import VueAxios from 'vue-axios'
import api from '@/api/api'
import { userinfo } from '@/utils/userinfo'

router.beforeEach((to, from, next) => {
    /* 路由发生改变时修改页面 title */
    const title: string = to.meta.title as string
    if (title) {
        document.title = title;
    }
    next();
});

router.afterEach((to) => {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
    (userinfo as any).in_userinfo = to.meta.isUserinfo;
    (userinfo as any).in_preview = to.meta.isPreview;
});

const app = createApp(App)
app.use(naive)
app.use(router)
app.use(VueAxios, Request.init())
app.config.globalProperties.$api = api
app.mount('#app')
